package io.renren.modules.work.controller;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.common.validator.ValidatorUtils;
import io.renren.modules.work.entity.ArticalmessageEntity;
import io.renren.modules.work.service.ArticalmessageService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;
import java.util.UUID;

/**
 * 文章评论表
 *
 * @author kylin
 * @email 1360315221@qq.com
 * @date 2019-03-14 21:51:12
 */
@RestController
@RequestMapping("work/articalmessage")
public class ArticalmessageController {
    @Autowired
    private ArticalmessageService articalmessageService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("work:articalmessage:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = articalmessageService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("work:articalmessage:info")
    public R info(@PathVariable("id") Integer id){
        ArticalmessageEntity articalmessage = articalmessageService.getById(id);

        return R.ok().put("articalmessage", articalmessage);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("work:articalmessage:save")
    public R save(@RequestBody ArticalmessageEntity articalmessage){

        articalmessage.setCratetime(new Date());
        String uuid = UUID.randomUUID().toString();
        articalmessage.setUuid(uuid);

        articalmessageService.save(articalmessage);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("work:articalmessage:update")
    public R update(@RequestBody ArticalmessageEntity articalmessage){
        ValidatorUtils.validateEntity(articalmessage);
        articalmessageService.updateById(articalmessage);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("work:articalmessage:delete")
    public R delete(@RequestBody Integer[] ids){
        articalmessageService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
